<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>嘻嘻嘻哈哈哈博客</title>
    <link rel="stylesheet" type="text/css" href="../static/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../static/css/blog.css">
    <script src="../static/js/jquery.min.js"></script>
</head>
<body class="user-select">
<header class="header">
    <nav class="navbar navbar-default" id="navbar1"
         style="opacity: 0.9;z-index: 9999;">
        <div class="container" id="nav">
            <div class="navbar-header logo-site">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#header-navbar" aria-expanded="false"><span class="sr-only"></span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
                <h1 class="logo hvr-bounce-in">
                    <a href="/" title="嘻嘻嘻哈哈哈博客">嘻嘻嘻哈哈哈博客</a>
                </h1>
            </div>
        </div>
    </nav>
</header>
<section class="container" id="detail">
    <div class="content-wrap">
        <div class="content">
            <header class="article-header">
                <h1 class="article-title"><a href="javascript:;">spring-boot整合ehcache实现缓存机制</a></h1>
                <div class="article-meta">
                    <span class="item article-meta-time">
                        <time class="time" data-toggle="tooltip" data-placement="bottom"><i class="glyphicon glyphicon-time"></i> <span>Wed Sep 23 11:57:21 CST 2020</span></time>
                    </span>
                </div>
            </header>
            <article class="article-content" style="height: auto !important;"><p><br></p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　EhCache 是一个纯Java的进程内缓存框架，具有快速、精干等特点，是Hibernate中默认的CacheProvider。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　ehcache提供了多种缓存策略，主要分为内存和磁盘两级，所以无需担心容量问题。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　spring-boot是一个快速的集成框架，其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置，从而使开发人员不再需要定义样板化的配置。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　由于spring-boot无需任何样板化的配置文件，所以spring-boot集成一些其他框架时会有略微的不同。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　1.spring-boot是一个通过maven管理的jar包的框架，集成ehcache需要的依赖如下</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div><pre style="margin-bottom: 0px; line-height: 1.42857; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
     <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-context-support<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
         <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>net.sf.ehcache<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
      <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>ehcache<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
          <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>2.8.3<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>        </pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div></div><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　具体pom.xml文件如下</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div><pre style="margin-bottom: 0px; line-height: 1.42857; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;?</span><span style="color: rgb(255, 0, 255); line-height: 1.5 !important;">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">?&gt;</span>
<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">project </span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">xmlns</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="http://maven.apache.org/POM/4.0.0"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> xmlns:xsi</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">
    xsi:schemaLocation</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">modelVersion</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>4.0.0<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">modelVersion</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>com.lclc.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>boot-cache<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>0.0.1-SNAPSHOT<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">&lt;!--</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;"> Inherit defaults from Spring Boot </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">--&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">parent</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-boot-starter-parent<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>1.1.3.RELEASE<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">parent</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencies</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-boot-starter-web<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-boot-starter-data-jpa<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-boot-starter-thymeleaf<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>mysql<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>mysql-connector-java<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>com.google.guava<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>guava<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>17.0<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-context-support<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>net.sf.ehcache<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>ehcache<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>2.8.3<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">version</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependency</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencies</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencyManagement</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencies</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencies</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">dependencyManagement</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">build</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">plugins</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">plugin</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
                <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>org.springframework.boot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">groupId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
                <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-boot-maven-plugin<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">artifactId</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">plugin</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">plugins</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">build</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repositories</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-snapshots<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>http://repo.spring.io/snapshot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">snapshots</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
                <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">enabled</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>true<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">enabled</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">snapshots</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-milestones<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>http://repo.spring.io/milestone<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">repositories</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepositories</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-snapshots<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>http://repo.spring.io/snapshot<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>spring-milestones<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">id</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>http://repo.spring.io/milestone<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">url</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
        <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepository</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">pluginRepositories</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>

<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">project</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div></div><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;　　2.使用ehcache，我们需要一个ehcache.xml来定义一些cache的属性。</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div><pre style="margin-bottom: 0px; line-height: 1.42857; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;?</span><span style="color: rgb(255, 0, 255); line-height: 1.5 !important;">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">?&gt;</span>
<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">ehcache </span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">xmlns:xsi</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> xsi:noNamespaceSchemaLocation</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="http://ehcache.org/ehcache.xsd"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">
  updateCheck</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span>
          <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">diskStore </span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">path</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="java.io.tmpdir/Tmp_EhCache"</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">/&gt;</span>
           <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">defaultCache </span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">eternal</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> maxElementsInMemory</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="1000"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> overflowToDisk</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> diskPersistent</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">
    timeToIdleSeconds</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="0"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> timeToLiveSeconds</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="600"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> memoryStoreEvictionPolicy</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="LRU"</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">/&gt;</span>

            <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">cache </span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">name</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="demo"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> eternal</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> maxElementsInMemory</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="100"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> overflowToDisk</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> diskPersistent</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="false"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;">
    timeToIdleSeconds</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="0"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> timeToLiveSeconds</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="300"</span><span style="color: rgb(255, 0, 0); line-height: 1.5 !important;"> memoryStoreEvictionPolicy</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">="LRU"</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">/&gt;</span>

<span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&lt;/</span><span style="color: rgb(128, 0, 0); line-height: 1.5 !important;">ehcache</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div></div><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;　　解释下这个xml文件中的标签。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　(1).<span style="color: rgb(128, 0, 0);">diskStore：</span>&nbsp;为缓存路径，ehcache分为内存和磁盘两级，此属性定义磁盘的缓存位置。参数解释如下：　　　　<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 　　　　user.home – 用户主目录<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 　　　 　user.dir&nbsp; – 用户当前工作目录<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;　　　　&nbsp; java.io.tmpdir – 默认临时文件路径</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　(2).<span style="color: rgb(128, 0, 0);">defaultCache：<span style="color: rgb(0, 0, 0);">默认缓存策略，当ehcache找不到定义的缓存时，则使用这个缓存策略。只能定义一个。</span></span></p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;"><span style="color: rgb(128, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (3).<span style="color: rgb(128, 0, 0);">cache</span>：自定缓存策略，为自定义的缓存策略。参数解释如下：</span></span></p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;"><span style="color: rgb(128, 0, 0);"><span style="color: rgb(0, 0, 0);">　　　 cache元素的属性：&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name：缓存名称&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxElementsInMemory：内存中最大缓存对象数&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxElementsOnDisk：硬盘中最大缓存对象数，若是0表示无穷大&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eternal：true表示对象永不过期，此时会忽略timeToIdleSeconds和timeToLiveSeconds属性，默认为false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; overflowToDisk：true表示当内存缓存的对象数目达到了maxElementsInMemory界限后，会把溢出的对象写到硬盘缓存中。注意：如果缓存的对象要写入到硬盘中的话，则该对象必须实现了Serializable接口才行。&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diskSpoolBufferSizeMB：磁盘缓存区大小，默认为30MB。每个Cache都应该有自己的一个缓存区。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diskPersistent：是否缓存虚拟机重启期数据&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diskExpiryThreadIntervalSeconds：磁盘失效线程运行时间间隔，默认为120秒&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeToIdleSeconds： 设定允许对象处于空闲状态的最长时间，以秒为单位。当对象自从最近一次被访问后，如果处于空闲状态的时间超过了timeToIdleSeconds属性值，这个对象就会过期，EHCache将把它从缓存中清空。只有当eternal属性为false，该属性才有效。如果该属性值为0，则表示对象可以无限期地处于空闲状态&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeToLiveSeconds：设定对象允许存在于缓存中的最长时间，以秒为单位。当对象自从被存放到缓存中后，如果处于缓存中的时间超过了 timeToLiveSeconds属性值，这个对象就会过期，EHCache将把它从缓存中清除。只有当eternal属性为false，该属性才有效。如果该属性值为0，则表示对象可以无限期地存在于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性，才有意义&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memoryStoreEvictionPolicy：当达到maxElementsInMemory限制时，Ehcache将会根据指定的策略去清理内存。可选策略有：LRU（最近最少使用，默认策略）、FIFO（先进先出）、LFU（最少访问次数）。&nbsp;&nbsp;</span></span></p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;"><span style="color: rgb(128, 0, 0);"><span style="color: rgb(0, 0, 0);">　　3.将ehcache的管理器暴露给spring的上下文容器，</span></span></p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;"><span style="color: rgb(128, 0, 0);"><span style="color: rgb(0, 0, 0);">　　</span></span></p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div><pre style="margin-bottom: 0px; line-height: 1.42857; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">@Configuration
</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">//</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;"> 标注启动了缓存</span>
<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">@EnableCaching
</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">class</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> CacheConfiguration {

    </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">/*</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">
     * ehcache 主要的管理器
     </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">*/</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">
    @Bean(name </span>= "appEhCacheCacheManager"<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">)
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){
        </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">return</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">new</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> EhCacheCacheManager (bean.getObject ());
    }

    </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">/*</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">
     * 据shared与否的设置,Spring分别通过CacheManager.create()或new CacheManager()方式来创建一个ehcache基地.
     </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">*/</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">
    @Bean
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){
        EhCacheManagerFactoryBean cacheManagerFactoryBean </span>= <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">new</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> EhCacheManagerFactoryBean ();
        cacheManagerFactoryBean.setConfigLocation (</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">new</span> ClassPathResource ("conf/ehcache-app.xml"<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">));
        cacheManagerFactoryBean.setShared (</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">true</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">);
        </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">return</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> cacheManagerFactoryBean;
    }
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div></div><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;&nbsp; 　　　　<span style="color: rgb(0, 0, 0);">@Configuration</span>：为spring-boot注解，主要标注此为配置类，优先扫描。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp; 　　　　<span style="color: rgb(0, 0, 0);">@Bean</span>：向spring容器中加入bean。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　至此所有的配置都做好了，通过spring-boot进行集成框架就是这么简单。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　4.使用ehcache</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　使用ehcache主要通过spring的缓存机制，上面我们将spring的缓存机制使用了ehcache进行实现，所以使用方面就完全使用spring缓存机制就行了。<br>　　　　具体牵扯到几个注解：</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　@Cacheable：负责将方法的返回值加入到缓存中，参数3<br>　　　　@CacheEvict：负责清除缓存，参数4</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　　参数解释：</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　value：缓存位置名称，不能为空，如果使用EHCache，就是ehcache.xml中声明的cache的name<br>　　　　key：缓存的key，默认为空，既表示使用方法的参数类型及参数值作为key，支持SpEL<br>　　　　condition：触发条件，只有满足条件的情况才会加入缓存，默认为空，既表示全部都加入缓存，支持SpEL</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　allEntries：CacheEvict参数，true表示清除value中的全部缓存，默认为false</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　不多说，直接上代码：</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div><pre style="margin-bottom: 0px; line-height: 1.42857; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">@Service
</span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">class</span> CacheDemoServiceImpl <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">implements</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> CacheDemoService {

    </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">/**</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">
     * 缓存的key
     </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">*/</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">static</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">final</span> String THING_ALL_KEY   = "\"thing_all\""<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">;
    </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">/**</span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">
     * value属性表示使用哪个缓存策略，缓存策略在ehcache.xml
     </span><span style="color: rgb(0, 128, 0); line-height: 1.5 !important;">*/</span>
    <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">static</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">final</span> String DEMO_CACHE_NAME = "demo"<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">;
   
    @CacheEvict(value </span>= DEMO_CACHE_NAME,key =<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> THING_ALL_KEY)
    @Override
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">void</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> create(Thing thing){
        Long id </span>=<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> getNextId ();
        thing.setId (id);
        data.put (id, thing);
    } 
      
     @Cacheable(value </span>=<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> DEMO_CACHE_NAME,key = "#thing.getId()+'thing'")
    @Override
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> Thing findById(Long id){
        System.err.println (</span>"没有走缓存！" +<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> id);
        </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">return</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> data.get (id);
    }

      @Cacheable(value </span>= DEMO_CACHE_NAME,key =<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> THING_ALL_KEY)
    @Override
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> List&lt;Thing&gt;<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> findAll(){
        </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">return</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> Lists.newArrayList (data.values ());
    }
   
   </span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">
      @Override
    @CachePut(value </span>= DEMO_CACHE_NAME,key = "#thing.getId()+'thing'"<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;">)
    @CacheEvict(value </span>= DEMO_CACHE_NAME,key =<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> THING_ALL_KEY)
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> Thing update(Thing thing){
        System.out.println (thing);
        data.put (thing.getId (), thing);
        </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">return</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> thing;
    }

    @CacheEvict(value </span>=<span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> DEMO_CACHE_NAME)
    @Override
    </span><span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">public</span> <span style="color: rgb(0, 0, 255); line-height: 1.5 !important;">void</span><span style="color: rgb(0, 0, 0); line-height: 1.5 !important;"> delete(Long id){
        data.remove (id);
    }
   
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: rgb(86, 182, 233); background-color: rgb(245, 245, 245) !important; border: none !important;"></a></span></div></div><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">　　　　5.只需要通过注解在service层方法上打注解便可以使用缓存，在find**上存入缓存，在delete**,update**上清除缓存。</p><p style="margin-top: 10px; margin-right: auto; margin-left: auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px;">&nbsp;</p></article>
            <div class="relates">
                <div class="title">
                    <h3>相关推荐</h3>
                </div>
                <ul>
                    <li>
                        <a href="/news/detail_112.html"> SpringBoot 在启动时运行代码</a>
                    </li>
                    <li>
                        <a href="/news/detail_110.html">spring boot 图片上传后的图片读取路径在win与linux环境配置的差别</a>
                    </li>
                    <li>
                        <a href="/news/detail_109.html">spring-boot整合ehcache实现缓存机制</a>
                    </li>
                    <li>
                        <a href="/news/detail_108.html">spring boot ehcache整合</a>
                    </li>
                    <li>
                        <a href="/news/detail_100.html">springboot thymeleaf和shiro 整合——按钮可见性</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</section>
<footer class="footer">
    <div class="container">
        <p>本站[<a href="http://xiaochancy.gitee.io/java/">嘻嘻嘻哈哈哈博客</a>]的部分内容来源于网络，若侵犯到您的利益，请联系站长删除！谢谢！Powered By [
        </p>
    </div>
    <div id="gotop"><a class="gotop"></a></div>
</footer>
<script src="../static/js/bootstrap.min.js"></script>
<script src="../static/js/blog.js"></script>
</body>
</html>
